home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15189 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Memory deallocation and linked lists
  5. Date: 17 Apr 1996 08:47:16 -0700
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4l33q4INN8tt@keats.ugrad.cs.ubc.ca>
  8. References: <4l1hpk$hk5@alice.walrus.com> <4l2tqk$pt1@gcsin3.geccs.gecm.com>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4l2tqk$pt1@gcsin3.geccs.gecm.com>,
  12. Richard Gilchrist  <richard.gilchrist@gecm.com> wrote:
  13. >warrenj@walrus.com (Warren Johnson) wrote:
  14. >>Greetings!
  15. >>Let us suppose I have a singularly linked list.  If i free up the first 
  16. >>node, will all of the rest of the nodes be freed up as well? Free 
  17. >>meaning, using the borland command free().  Do I have to free up each node
  18. >>seperately? Something I've never actually known >:). Thanks in advance.
  19.  
  20. >Warren,
  21. >
  22. >I can't remember what the borland command free() does exactly, but  the UNIX c 
  23. >command free() requires you to must traverse the list and free each element of the 
  24. >list, and I don't think that the borland command  will be much different from the 
  25. >UNIX free command.
  26.  
  27. free is a standard defined library _function_, not a Borland or UNIX
  28. ``command''. It is defined by the C language standard to have consistent
  29. semantics across all implementations.
  30.  
  31. malloc() and free() have no concept of the data structure that you are building
  32. using the allocated units. They have no idea that the list node you are freeing
  33. contains pointers to other nodes that you also want to free, or that other
  34. nodes point to it. As far as these allocator functions are concerned, the
  35. contents of the node are just a bunch of bytes.
  36. -- 
  37. I'm not really a jerk, but I play one on Usenet.
  38.